#include "Ball.h"

using namespace std;

    Ball::Ball(const Point2& startPos, const std::map<std::string, Image>& images) : DynamicSprite(images, "boll", startPos, Vector2(60,60), 1) {}
    
    
    
    Ball* Ball::getInstance(const Point2& startPos, const std::map<std::string, Image>& images){
        return new Ball(startPos, images);
    }


    void Ball::update(const std::set<Sprite*>& sprites, const double dt){
        //std::cout << "hi";
        DynamicSprite::update(sprites, dt);
        std::set<Sprite*> collided = Sprite::checkCollisions(sprites);
  
		for(std::set<Sprite*>::const_iterator i = collided.begin(); i != collided.end(); ++i){
			(*i)->onCollision();
			std::cout << "for each collision" << std::endl;
        }
        
    }
    
    void Ball::onCollision(){
        std::cout << "ballcollide-test" << std::endl;
        
        setVel(-getVel());
    }
